package xFGE.Loader
{
	
	import flash.display.Bitmap;
	import flash.display.Loader;
	import flash.events.*;
		
	internal class ImageLoader extends LoaderBase
	{	/** 加载器 */
		private var _loader:Loader;
		
		public function ImageLoader()
		{
			//TODO: implement function
			super(xLoader.LOADER_TYPE_IMGE);
			// create loader
			_loader = new Loader();
			//绑定消息事件处理：
			_loader.contentLoaderInfo.addEventListener(Event.OPEN,super.onStart);
			_loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,super.onProgress);
			_loader.contentLoaderInfo.addEventListener(Event.COMPLETE,onComplete);
			_loader.contentLoaderInfo.addEventListener(HTTPStatusEvent.HTTP_STATUS,super.onHttpStatus);
			_loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,super.onIOError);
		}
		
		override public function Load(resourceObj:ResourceObj):void
		{
			super.Load(resourceObj);
			try{
				_loader.load(resourceObj.url);
			}catch(e:SecurityError){
				trace(e);
			}
		}
		
		override protected  function onComplete(eveObj:Event):void
		{
			_content = (_loader.content as Bitmap).bitmapData;
			super.onComplete(eveObj);
		}
		
		override public function Clear():void
		{
			_loader.contentLoaderInfo.removeEventListener(Event.OPEN,super.onStart);
			_loader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS,super.onProgress);
			_loader.contentLoaderInfo.removeEventListener(Event.COMPLETE,onComplete);
			_loader.contentLoaderInfo.removeEventListener(HTTPStatusEvent.HTTP_STATUS,super.onHttpStatus);
			_loader.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR,super.onIOError);
			
		}
	}
}